<template>
<div>
  <div class="loader-base" v-if="showLoad"><div class="loader-wrap"></div></div>
  <header-box :title="'我的待办'" :hasArrow="true"></header-box>
  <tab bar-active-color="#BFBFBF" :line-width='1' active-color="#7CA7F3">
    <tab-item selected @on-item-click="onItemClick(2)">待处理</tab-item>
    <tab-item @on-item-click="onItemClick(5)">已处理</tab-item>
  </tab>
  <list-card :listDatas='listDatas' :totalLength='totalLength' 
             :url="'/dealt/detail'"
             @changePage="getData">
  </list-card>
</div>
</template>
<script>
import listCard from "@/components/share/listCard.vue";
export default {
  name:'dealtList',
  components:{
    listCard
  },
  data() {
    return {
      showLoad:false,
      listDatas:[],
      pageIndex:1,
      totalLength:0,
      status:2,
    };
  },
  watch: {

  },
  computed: {
    userInfo(){
      return localStorage.UserInfo?JSON.parse(localStorage.UserInfo):'';
    }
  },
  created() {
    this.listDatas = [];
    this.getData();
  },
  // -----------------缓存start
  activated(){
    if(sessionStorage.dealtIndex){
      var delIndex = sessionStorage.dealtIndex;
      this.totalLength = this.totalLength - 1;
      this.listDatas.splice(delIndex,1);
      //清楚数据缓存
      sessionStorage.removeItem("dealtIndex");
    }
  },
  // -----------------缓存end
  methods: {
    onItemClick(val){
      this.status = val;
      this.pageIndex = 1;
      this.listDatas = [];
      this.getData();
    },
    getData(){
      this.showLoad = true;
      let data={
        "pagesize": 99999999,
        "pageindex": this.pageIndex,
        "staffid": this.userInfo.staffid,
        "floworganiser": "", // 流程发起人名字，如：王超
        "organiserstarttime": "",
        "organiserendtime": "",
        'status':this.status//2 待处理   5 已处理
      };
      let _this = this;
      this.Ajax.post('WorkflowService/MyWFToDoListQuery',data).then(function(resp) {
        if(resp.code == 'SUCC'){
          let result = JSON.parse(resp.data);
          let todolist = JSON.parse(result.data);
           console.log(todolist,"代办列表")
          //列表类型数组重定义
          for(let i in todolist){
            todolist[i].applicant = todolist[i].floworganiser;
            todolist[i].applydate = '发起日期：'+todolist[i].organisetime;
            todolist[i].deptname = todolist[i].floworganiserdept;
            todolist[i].datastatus = todolist[i].status;
            todolist[i].dealt = '1';//自定义参数表示是我的待办数据
            // console.log(todolist[i].todotype)
            if(todolist[i].todotype=='4'){
              todolist[i].classify = '请假'
            }else if(todolist[i].todotype=='2'){
              todolist[i].classify = '加班'
            }else if(todolist[i].todotype=='3'){
              todolist[i].classify = '差旅报销'
            }else if(todolist[i].todotype=='1'){
              todolist[i].classify = '出差'
            }else if(todolist[i].todotype=='5'){
              todolist[i].classify = '外出'
            }
          }
          _this.totalLength = result.recordcount;
          _this.listDatas = _this.listDatas.concat(todolist);
          _this.pageIndex++;
        }else{
          _this.$vux.toast.show({
            type: "warn", //success, warn, cancel, text
            text: resp.message
          });
        }
        _this.showLoad = false;
      });
    }
  }
};
</script>